package com.itheima.project.web;

import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.trade.TradingEnum;
import com.itheima.project.face.JsapiPayFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.trade.TradingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName JsapiPayController.java
 * @Description jsapi支付控制
 */
@RequestMapping("trade-jsapi")
@RestController
@Api(tags = "Jsapi支付controller")
public class JsapiPayController {

    @Autowired
    JsapiPayFace jsapiPayFace;

    /***
     * @description 统一jsapi交易预创建
     * 商户系统先调用该接口在微信支付服务后台生成预支付交易单，返回正确的预支付交易会话标识后再按Native、
     * JSAPI、APP等不同场景生成交易串调起支付。
     * @param tradingVo 交易订单
     * @return  支付串码
     */
    @PostMapping("create-jsapi-trading")
    @ApiOperation(value = "统一收单线下交易",notes = "统一收单线下交易")
    @ApiImplicitParam(name = "tradingVo",value = "交易单",required = true,dataType = "TradingVo")
    ResponseWrap<TradingVo> createJsapiTrading(@RequestBody TradingVo tradingVo){
        TradingVo tradingVoResult = jsapiPayFace.createJsapiTrading(tradingVo);
        return ResponseWrapBuild.build(TradingEnum.SUCCEED,tradingVoResult);
    }
}
